package com.sicheng.lc.周赛.分类.位运算;

/**
 * @author zsc
 * @version 1.0
 * @date 2022/9/25 19:54
 */
public class 按位与最大的最长子数组 {
    //https://leetcode.cn/problems/longest-subarray-with-maximum-bitwise-and/


    public int longestSubarray(int[] nums) {
        //找到数组最大值的 最大连续长度
        int x = 0;
        int d = 0;
        int res = 0;
        for (int i = 1; i < nums.length; i++) {
            if (nums[i] > nums[x]) {
                x = i;
                d = 1;
                res = 1;
            } else if (nums[i] == nums[x]) {
                if (nums[i - 1] == nums[i])
                    d = i - x + 1;
                else {
                    x = i;
                    d = 1;
                }
            }
            res = Math.max(res, d);
        }
        return res;
    }

    public static void main(String[] args) {
        按位与最大的最长子数组 s = new 按位与最大的最长子数组();
        int[] nums = {1, 2, 3, 3, 2, 2};
        System.out.println(s.longestSubarray(nums));
    }
}
